package com.caissa.springboot.starter.msg.service;

import cn.hutool.core.util.IdUtil;
import com.caissa.retail.msg.export.common.constant.KafkaTopicConstant;
import com.caissa.retail.msg.export.common.enums.MessageTypeEnum;
import com.caissa.retail.msg.export.common.enums.ResendTimeEnum;
import com.caissa.retail.msg.export.po.MsgInfoPo;
import com.caissa.retail.msg.export.po.wechat.qiketu.QiketuMsgPo;
import com.base.springboot.starter.kafka.service.KafkaService;
import com.base.springboot.starter.msg.config.ResendPo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.support.SendResult;
import org.springframework.util.concurrent.ListenableFuture;

import java.util.Date;

/**
 * 企客兔消息管理
 * @Author：zhangqiang
 * @Date 2020/9/4 18:13
 */
@Slf4j
public class QiketuService {
    @Autowired
    private KafkaService kafkaService;

    /**
     * 多人群发
     *
     * @param qiketuMsgPo
     * @return
     */
    public ListenableFuture<SendResult<String, Object>> sendQiketuUserMsg(QiketuMsgPo qiketuMsgPo,  ResendPo resendPo) {
        MsgInfoPo msgInfoPo = new MsgInfoPo();
        msgInfoPo.setId(IdUtil.simpleUUID());
        msgInfoPo.setMessageType(MessageTypeEnum.QKT_USER);
        msgInfoPo.setSendTotalNum(resendPo.getSendTotalNum());
        msgInfoPo.setResendTime(resendPo.getResendTimeEnum());
        msgInfoPo.setSendDateTime(new Date());
        msgInfoPo.setMessageInfo(qiketuMsgPo);
        log.info("sendQiketuUserMsgPo:{}-{} ",KafkaTopicConstant.SEND_QKT_USER_TOPIC, msgInfoPo);
        return kafkaService.send(KafkaTopicConstant.SEND_QKT_USER_TOPIC, msgInfoPo);
    }

    /**
     * 单人多个群的群发
     *
     * @param qiketuMsgPo
     * @return
     */
    public ListenableFuture<SendResult<String, Object>> sendQiketuRoomMsg(QiketuMsgPo qiketuMsgPo,  ResendPo resendPo) {
        MsgInfoPo msgInfoPo = new MsgInfoPo();
        msgInfoPo.setId(IdUtil.simpleUUID());
        msgInfoPo.setMessageType(MessageTypeEnum.QKT_ROOM);
        msgInfoPo.setSendTotalNum(resendPo.getSendTotalNum());
        msgInfoPo.setResendTime(resendPo.getResendTimeEnum());
        msgInfoPo.setSendDateTime(new Date());
        msgInfoPo.setMessageInfo(qiketuMsgPo);
        log.info("sendQiketuRoomMsgPo:{}-{} ",KafkaTopicConstant.SEND_QKT_ROOM_TOPIC, msgInfoPo);
        return kafkaService.send(KafkaTopicConstant.SEND_QKT_ROOM_TOPIC, msgInfoPo);
    }
}
